package com.study.d4_thread;

public class Test1 {
    public static void main(String[] args) {
        //目标：掌握线程创建方式1：继承Thread类：优点是编码简单，缺点是线程类已经继承Thread无法继承其他类，不利于功能的扩展
        Thread t = new MyThread("haha");
        //start会自动执行线程的run方法
        t.start();
        //若直接调用run，cpu不会注册新线程执行，此时相当于还是单线程
//        t.run();

        Thread thread = Thread.currentThread();
        thread.setName("huahua");
        System.out.println(thread.getName());
        for (int i = 0; i < 4; i++) {
            System.out.println(thread.getName()+"线程输出："+i);
        }
    }
}
class MyThread extends Thread{
    public MyThread(String haha) {
        super(haha);
    }

    @Override
    public void run() {
        for (int i = 0; i < 4; i++) {
            System.out.println(this.getName()+"线程输出："+i);
        }
    }
}